import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

import { resolve } from 'path' //引入node的path模块 这里报错


import createVitePlugins from './vite/plugins'

// https://vitejs.dev/config/
export default defineConfig(({ mode, command })=>{
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      createVitePlugins(mode, command === 'build')
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, './src')
      }
    },
    server: {
      proxy: {
        '/dev-api': {
          target: 'http://127.0.0.1:9080', // 目标服务器地址
          changeOrigin: true, // 是否改变源地址
          rewrite: (path) => path.replace(/^\/dev-api/, ''), // 重写路径
          // 可以配置更多选项，如 logLevel, timeout 等
        },
      },
    },
  }
})
